package Network.UDP;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class DictServer extends Echoserver {

    private Map<String,String> dict = new HashMap<>();

    public DictServer(int port) throws IOException {
        super(port);

        dict.put("apple","苹果");
        dict.put("banana","香蕉");
        dict.put("orange","橘子");
        dict.put("watermelon","西瓜");
        dict.put("pear","梨");
        dict.put("grape","葡萄");
        dict.put("pineapple","菠萝");
        dict.put("strawberry","草莓");
        dict.put("cherry","樱桃");
        dict.put("mango","芒果");
    }
    
    @Override
    public String process(String request) {
        //方法重写，本质上就是对父类的功能进行扩展
        //本来父类是没有“翻译”功能的，通过重写把功能加上
        return dict.getOrDefault(request,"查无此词");
    }

    public static void main(String[] args) throws IOException {
        DictServer dictServer = new DictServer(9090);
        dictServer.start();
    }

}
